//
//  StudyReportScoreListView.m
//  jzyParents
//
//  Created by 任辰东 on 2025/3/5.
//

#import "StudyReportScoreListView.h"
#import "StudyReportScoreTCell.h"

@interface StudyReportScoreListView ()<UITableViewDelegate,UITableViewDataSource>
@property (nonatomic, copy) NSArray *dataSourceArray;
@property (strong, nonatomic) UITableView *myTabelView;

@end

@implementation StudyReportScoreListView

-(void)configViewWithData:(NSArray <Kaoshi_score_listItem *> *)data
{
    self.dataSourceArray = [NSArray arrayWithArray:data];
    [self.myTabelView mas_remakeConstraints:^(MASConstraintMaker *make) {
       
        make.top.left.right.equalTo(self);
        make.height.mas_equalTo(35 * self.dataSourceArray.count);
        make.bottom.equalTo(self).offset(0);
    }];
    [self.myTabelView reloadData];
}

- (void)setupViews
{
    [self addSubview:self.myTabelView];
}

- (void)setupLayout
{
    
    [self.myTabelView mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.edges.equalTo(self);
    }];

}

#pragma mark - UITableViewDelegate,UITableViewDataSource

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    StudyReportScoreTCell *cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([StudyReportScoreTCell class])];
    cell.backgroundColor = [UIColor clearColor];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    if (indexPath.row < self.dataSourceArray.count) {
        Kaoshi_score_listItem *model = self.dataSourceArray[indexPath.row];
        [cell configCellWithModel:model];
        
        WeakSelf
        [cell setScoreBtnBLock:^{
            
            StrongSelf
            if (self.scoreBtnBLock) {
                self.scoreBtnBLock(model);
            }
        }];
        
        [cell setCardBtnBLock:^{
            
            StrongSelf
            if (self.cardBtnBLock) {
                self.cardBtnBLock(model);
            }
        }];
    }
    

    
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 35;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.dataSourceArray.count;
}

#pragma mark -- lazyload

- (UITableView *)myTabelView{
    if (!_myTabelView) {
        _myTabelView = [[UITableView alloc]initWithFrame:CGRectZero];
        _myTabelView.delegate = self;
        _myTabelView.dataSource = self;
        _myTabelView.backgroundColor = [UIColor clearColor];
        _myTabelView.scrollEnabled = NO;
        _myTabelView.separatorColor = [UIColor clearColor];
        [_myTabelView registerClass:[StudyReportScoreTCell class] forCellReuseIdentifier:NSStringFromClass([StudyReportScoreTCell class])];
        [_myTabelView addBottomLine];
    }
    return _myTabelView;
}

-(NSArray *)dataSourceArray
{
    if (!_dataSourceArray) {
        _dataSourceArray = [NSArray array];
    }
    return _dataSourceArray;
}


@end
